using System;
using System.Collections.Generic;
using System.IO;
using JsonRpcGen.TypeHandler;
using Newtonsoft.Json.Linq;

namespace JsonRpcGen.ParameterHandler
{
    internal class ObjectParamHandler : ParamHandler
    {
        private readonly string _className;
        private ObjectTypeHandler _typeHandler;
        private bool _done;
        private JToken _props;

        public ObjectParamHandler(string name, JToken parameter, string className):base(name,className)
        {
            _className = className;
            _props = parameter["properties"];
            if (_props==null)
            {
                throw new ArgumentNullException();
            }
            _typeHandler = new ObjectTypeHandler(_props);
        }

        public override void WriteType(StreamWriter writer, Dictionary<string, string> replacements)
        {
            if (!_done)
            {
                _typeHandler.WriteClass(writer, _className, replacements);
                _done = true;
            }
        }
    }
}